import requests
import pymongo
from pyquery import PyQuery as pq
requests.packages.urllib3.disable_warnings()
client = pymongo.MongoClient("mongodb://localhost:27017/")
db = client.Advanced
collection = db.Movie
for i in range(1, 11):
    url = f"https://ssr1.scrape.center/page/{i}"
    res = requests.get(url, verify=False)
    doc = pq(res.text)
    divs = doc("div")
    for div in divs.items():
        if div.attr("class") == "el-card item m-t is-hover-shadow":
            img = div(".cover")
            img_url = img.attr("src")
            title = div(".m-b-sm").text()
            tags = div("button")
            t = []
            for tag in tags.items():
                if tag.attr("class") == "el-button category el-button--primary el-button--mini":
                    t.append(tag.text())
            in_divs = div("div")
            for in_div in in_divs.items():
                if in_div.attr("class") == "m-v-sm info":
                    release_time = in_div.text()
            for p in div("p").items():
                if p.attr("class") == "score m-t-md m-b-n-sm":
                    score = p.text()
            data = {
                "img_url" : img_url,
                "title" : title,
                "tags" : t,
                "release_time" : release_time,
                "score" : score
            }
            print(data)
            collection.insert_one(data)
